#include <omp.h>
#include <random>
#include <iostream>
#include <cmath>
using namespace std;


// cal pi
double get_f(const double&x)
{
    return 4./(1+x*x);
}
//当作梯形面积
double cal_Trape_area(const double&x1,const double&x2 )
{
    double y1=get_f(x1);
    double y2=get_f(x2);
    return (y1+y2)*(x2-x1)*0.5f;
}
double cal_rec_area(const double&x1,const double&x2 )
{
    double temp=(x1+x2)/2;
    double y=get_f(temp);

    return y*(x2-x1);
}
int main(int argc, char** argv)
{
    int num_threads=32;
    int num_samples = 10000;
    double _delta=1/num_samples;
    double sum=0;

    # pragma omp parallel  for num_threads ( num_threads )
            for (int i = 0; i < num_samples; i++)
            {
                double x1 = 1. * i / num_samples;
                double x2 = 1. * (i + 1) / num_samples;
                #pragma omp critical
                { sum += cal_rec_area(x1, x2); }
            }





# pragma omp barrier
# pragma omp master
    {


        cout <<"Pi="<<sum << endl;
    }
}






